package com.xhc.system.controller.admin;

import com.xhc.server.domain.Resource;
import com.xhc.server.dto.ResourceDto;
import com.xhc.server.dto.PageDto;
import com.xhc.server.dto.ResponseDto;
import com.xhc.server.service.ResourceService;
import com.xhc.server.util.ValidatorUtil;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @version 1.0
 * @Author: XHC
 * @Date: 2023-12-19-17:58
 * @Description: 吃番茄不吃番茄酱
 * @注释:
 */
@RestController
@RequestMapping("/admin/resource")
public class ResourceController {

//    private static final Logger LOG = LoggerFactory.getLogger(ResourceController.class);
    public static final String BUSINESS_NAME = "资源";

    @javax.annotation.Resource
    private ResourceService resourceService;

    /**
     * 列表【查询】
     * @param pageDto
     * @return
     */
    @RequestMapping("/list")
    public ResponseDto list(@RequestBody PageDto pageDto){
        ResponseDto responseDto = new ResponseDto();
        resourceService.list(pageDto);
        responseDto.setContent(pageDto);
         return responseDto;
    }

    /**
     * 保存，id有值时更新，无值时新增
     * @param resourceDto
     * @return
     */
    @RequestMapping("/save")
    public ResponseDto save(@RequestBody String  jsonStr){
        // 保存校验
        ValidatorUtil.require(jsonStr, "资源");

        ResponseDto responseDto = new ResponseDto();
        resourceService.saveJson(jsonStr);
        return responseDto;
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseDto delete(@PathVariable String id){
        ResponseDto responseDto = new ResponseDto();
        resourceService.delete(id);
        return responseDto;
    }

       /**
     * 资源树查询
     * @return
     */
     @GetMapping("/load-tree")
      public  ResponseDto loadTree(){
         ResponseDto responseDto = new ResponseDto();
          List<ResourceDto> responseDtoList  = resourceService.loadTree();
          responseDto.setContent(responseDtoList);
          return responseDto;
     }

}
